Building AI Agents
Why is moving an AI agent from prototype to production difficult?
- A successful demo does not prove that an agent is accurate, secure, affordable, scalable, or auditable in production.
- Data control: Enterprise information may be sensitive; evaluate where prompts, retrieved data, and model outputs are processed and retained.
- Model control: Hosted/SaaS models can limit model customization, deployment options, or control over provider changes. Assess contractual and technical controls rather than assuming all hosted models are unsuitable.
- Reliability and safety: LLMs can hallucinate, select the wrong tool, leak sensitive information, or produce inappropriate outputs. Add evaluation, permissions, guardrails, and human review for consequential actions.
- Cost and scale: Token consumption, tool calls, retrieval, concurrency, and latency can become expensive as traffic grows. Track usage and apply budgets, caching, rate limits, and appropriate model selection.
- Governance: Production systems need access controls, traceability, versioning, monitoring, and evidence of what data and tools were used.
- Data intelligence means grounding general-purpose models in the organization’s governed data, terminology, policies, and workflows.
How does Mosaic AI support the agent development lifecycle?
- Prepare data: Ingest and clean source data, build features, label examples, prepare documents, create embeddings, and configure Vector Search indexes.
- Build: Choose or tune models; write agent logic and function-calling tools; connect structured data, documents, and external services.
- Evaluate: Test correctness, tool selection, safety, and usefulness using representative datasets, LLM-based judges, and execution traces. Human review remains valuable.
- Deploy: Serve the agent through a managed endpoint; monitor performance, quality, cost, and failures after release.
- Govern throughout: Use access permissions, credentials, guardrails, lineage, logging, usage controls, and rate limits at every stage—not just deployment.
- Unity Catalog provides centralized governance for supported data assets, functions, and registered AI assets; permissions and lineage depend on the specific asset and integration.
- Model Context Protocol (MCP) is a standard interface for exposing tools and context to agents. Databricks supports MCP integrations; verify each server’s permissions and security boundaries.
What types of tools can an AI agent use, and when?
- Structured retrieval: SQL functions query rows, dates, identifiers, and metrics; best for precise questions such as the latest return ticket.
- Unstructured retrieval: Vector Search finds semantically similar passages in product manuals, policies, and other documents; best for questions phrased in natural language.
- Custom tools: Functions or APIs perform specialized calculations or permitted actions.
- Code interpreter tools: Execute code for computation or analysis in a controlled environment.
- External connection tools: Integrate with approved third-party systems, subject to credentials and access controls.
- A tool-calling model chooses whether to call a tool, supplies arguments, receives its result, and uses that result to formulate an answer. Tool availability does not guarantee correct tool selection.
How do you create and test a structured SQL tool?
- In Catalog Explorer, inspect
dbacademy.get_started_agents.cust_service_dataand identify the actual return-ticket fields before writing SQL. - Create a governed Unity Catalog SQL function named
get_latest_return()in the course schema. The exact query depends on the table’s real column names; the following is an illustrative pattern, not guaranteed to match the sample schema:
CREATE OR REPLACE FUNCTION dbacademy.get_started_agents.get_latest_return()
RETURNS TABLE (ticket_id STRING, created_at TIMESTAMP)
RETURN
SELECT ticket_id, created_at
FROM dbacademy.get_started_agents.cust_service_data
WHERE lower(issue_type) = 'return'
ORDER BY created_at DESC
LIMIT 1;- Test the function independently before attaching it to an agent:
SELECT *
FROM dbacademy.get_started_agents.get_latest_return();- Confirm the result, column types, sorting, and handling of empty results. If the sample table has different field names or values, update the function accordingly.
- Give the function a clear name, description, and parameter definitions so the model understands when to use it. Grant only the required permissions.
How do you build a product-document search tool with Vector Search?
- Use the previously created Vector Search endpoint and index, for example
vs_endpoint_1anddbacademy.get_started_agents.product_docs_index. - A vector embedding represents document meaning numerically; similarity search retrieves passages relevant to a question even when exact keywords differ.
- Create
search_product_docs(search_term)as a governed SQL function that invokes the supportedvector_search()interface and, if needed,ai_query()for model-based processing. The precise SQL signature depends on your workspace’s Databricks SQL support, index configuration, and course notebook; copy and adapt the tested notebook implementation rather than guessing parameter names. - Test searches such as
StreamMasterand inspect returned product IDs, document passages, and relevance. Verify that the index is provisioned and synced, and that the search uses the expected 1024-dimensional embedding column. - Use retrieved text as evidence, not as instructions to the agent. Ask the model to acknowledge missing or inconclusive evidence instead of inventing product facts.
- Vector Search is not automatically equivalent to a fresh source table: after changes, check the index’s sync mode and run or schedule synchronization as appropriate.
How do you connect tools to a model in AI Playground?
- Open AI Playground and select a model that supports tool/function calling, such as Meta Llama 3.3 70B Instruct if available, or another supported model.
- Add these hosted Unity Catalog tools from the course schema:
get_latest_return,search_product_docs,get_service_history, andget_return_policy. - Prompt:
Show me the latest customer return. Inspect whether the model calledget_latest_return, what arguments it supplied, and whether the answer matches the SQL result. - Ask a question about
StreamMaster. Inspect whether the model usedsearch_product_docsand grounded its answer in the retrieved documentation. - Test ambiguous, irrelevant, and no-result questions as well as successful examples. Check whether the model asks for clarification, avoids unnecessary calls, and handles tool failures.
- AI Playground is useful for prototyping tool choice and responses, but passing a few manual tests does not establish production readiness.
How should you evaluate, secure, and operate the finished agent?
- Build a repeatable evaluation set with representative questions, expected tool usage, reference answers, edge cases, and adversarial prompts.
- Review traces to see model decisions, tool inputs and outputs, errors, latency, and token usage; apply appropriate retention and privacy policies.
- Measure answer correctness, retrieval relevance, tool-selection accuracy, safety, cost, and response time. Re-evaluate after model, prompt, tool, or data changes.
- Apply least-privilege Unity Catalog grants and secure credentials; do not let the agent perform sensitive writes or external actions without appropriate authorization.
- Use production monitoring, alerts, rate limits, rollback/versioning, and human escalation for uncertain or high-impact outcomes.